<template>
	<view class="content">
		<!-- 	<u--input shape="circle" placeholder="想去哪,搜一搜当地攻略" suffixIcon="search"
			suffixIconStyle="font-size: 29px;color: #909399"
			:customStyle="{backgroundColor:'#f6f6f6',padding:'15rpx 30rpx',boxSizing:' border-box'}"></u--input> -->
		<!-- <view class="title">
			<text></text>
			<text>热门景点美食推荐</text>
		</view> -->
		<view class="travel">
			<u-empty v-if="momentlist.length <= 0" mode="list" width="50%" textSize="30"
				icon="http://cdn.uviewui.com/uview/empty/list.png">
			</u-empty>
			<custom-waterfalls-flow v-else ref="waterfallsFlowRef" :value="momentlist" image-key="images" :column="2"
				:columnSpace="1.5" slot="slot{{index}}">
				<view class="travel-guide" v-for="(item,index) in momentlist" :key="index"
					@click="gomomentDeatil(item.id)">

					<view class="travel-guide-title">
						{{item.title}}
					</view>
					<view class="travel-guide-bottom">
						<view class="travel-guide-bottom-left">
							<image
								:src="item.avatar? $u.fileBaseUrl+ item.avatar :'../../static/images/me/default-avatar-orange.png' "
								mode="aspectFill"></image>

							<text>{{item.nickname}}</text>
						</view>
						<view class="travel-guide-bottom-right">
							<uni-icons type="chat" size="30" color="#ddd"></uni-icons>
							<text>{{item.commentNum == null ? 0 :item.commentNum}}</text>
						</view>
					</view>
				</view>
			</custom-waterfalls-flow>
		</view>
		<view class="bottom-shadow"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				momentlist: [],
				page: {
					pageSize: 10,
					pageNum: 1
				},
				total: 0,
			};
		},
		// 下拉刷新
		onPullDownRefresh() {
			// 刷新数据的逻辑
			this.page.pageNum = 1
			this.page.pageSize = 10
			this.getorderlist()
			// 模拟异步操作
			setTimeout(() => {
				// 刷新完成后，结束下拉刷新
				uni.stopPullDownRefresh();
			}, 1000);
			this.current = 0
		},
		// 上拉加载
		onReachBottom() {
			this.loadMore();
		},
		methods: {
			/* guideDetails(id) {
				uni.navigateTo({
					url: `/packagesIndex/pages/guideDetails/guideDetails?id=${id}`
				})
			}, */

			handleImages(data) {
				return data.map(item => Object.assign(item, {
					images: this.$u.fileBaseUrl + item.images.split(',')[0]
				}));
			},

			// 获取旅游攻略
			async getmomentlist() {
				let res = await this.$u.api.getmomentmyList(this.page)
				if (res.code == 200) {
					if (this.page.pageNum == 1) {
						this.momentlist = handleImages(res.rows);
					} else {
						// 如果不是第一页，追加数据
						this.momentlist = [...this.momentlist, ...handleImages(res.rows)];
						this.$refs.waterfallsFlowRef.refresh();
					}
					this.total = res.total;
				}
			},
			// 跳转攻略详情
			gomomentDeatil(id) {
				uni.navigateTo({
					url: `/packagesIndex/pages/guideDetails/guideDetails?id=${id}&type=${1}`
				})
			},
			// 上拉加载
			loadMore() {
				if (this.momentlist.length >= this.total) {
					uni.showToast({
						title: '没有更多攻略了',
						icon: "none"
					});
					return;
				}

				this.page.pageNum += 1;
				uni.showLoading({
					title: '加载中...'
				});

				this.getmomentlist().then(() => {
					uni.hideLoading();
				}).catch(error => {
					console.error('加载更多数据时出错:', error);
					uni.hideLoading();
					uni.showToast({
						title: '加载失败，请重试',
						icon: 'none'
					});
				});
			},
		},
		onShow() {
			this.getmomentlist()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		min-height: 100vh;
		background-color: #fff;
		padding: 0 10rpx env(safe-area-inset-bottom);

		.bottom-shadow {
			position: fixed;
			z-index: -1;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 200rpx;
			background: linear-gradient(to top, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0));
		}

		.title {
			display: flex;
			align-items: center;
			margin: 30rpx 0;

			text {
				font-weight: 600;
				font-size: 32rpx;

				&:nth-child(1) {
					width: 10rpx;
					height: 30rpx;
					display: block;
					background-color: $overall-color;
					margin-right: 15rpx;
				}
			}
		}

		.travel {
			width: 100%;
			min-height: calc(100vh - env(safe-area-inset-bottom));
			border-radius: 10rpx;
			padding: 10rpx;
			background-color: #e9e9e9;

			.travel-guide {
				background-color: #fff;
				border-radius: 10rpx;
				box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
				margin-bottom: 20rpx;

				.travel-guide-image {
					width: 320rpx;
				}

				.travel-guide-title {
					font-size: 24rpx;
					text-align: center;
				}

				.travel-guide-bottom {
					margin: 10rpx 0;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.travel-guide-bottom-left {
						image {
							width: 60rpx;
							height: 60rpx;
							vertical-align: middle;
							border-radius: 30rpx;
							margin-right: 10rpx;
						}

						text {
							font-size: 24rpx;
						}
					}

					.travel-guide-bottom-right {
						align-items: center;
						display: flex;
						color: #999999;
						font-size: 24rpx;
						gap: 5rpx;

						uni-icons {
							margin-top: 5rpx;
						}

						text {
							display: block;
						}
					}
				}
			}
		}
	}
</style>